<%@ page pageEncoding="utf-8" isELIgnored="false" %>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>校园超市管理系统</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/jsp/css/public.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/jsp/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/js/easyui/themes/icon.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/jsp/js/bootstrap/css/bootstrap.min.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/jsp/js/jQuery1.11.1.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui/jquery.easyui.min.js"></script>
    <%--  <script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery.pagination.js"></script>--%>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
        jQuery.noConflict();
        var  loginOut;
        var shanchu;
        var xiugai;
        var  daochu;
        jQuery(function($){
            daochu=function daochubill() {
                $.ajax({
                    url:"${pageContext.request.contextPath}/daochu",
                    type:"GET",
                    data:{},
                    statusCode: {
                        403: function() {
                           $.messager.alert("温馨提示","对不起，您无权访问","error");
                            //window.location.href = "login.html";
                        }
                    },
                    success:function (data) {
                        location.href="${pageContext.request.contextPath}/jsp/"+data.data+".jsp"
                    }
                });
            }
            xiugai=function xiugaibill() {
                var i=$("#checkboxs:checked").length;
                if(i>1){
                   $.messager.alert("温馨提示","只能选择一项","error");
                }else if(i<1){
                    $.messager.alert("温馨提示","请选择一项","error");
                }else{
                    location.href="${pageContext.request.contextPath}/billUpdate?id="+$("#checkboxs:checked").val();
                }
            }
            shanchu=function shanchubill() {
                var check = $("#checkboxs:checked").length;
                var  ids="";
                if (check==0){
                    $.messager.alert("温馨提示","请选择要删除的选项","question");
                }else{
                    $.messager.confirm("温馨提示","确定要删除吗？",function (r) {
                        if (r){
                            var checkboxs=$("#checkboxs:checked");
                            for(var i=0;i<checkboxs.length;i++){
                                ids+=checkboxs[i].value+',';
                            }
                            $.ajax({
                                url:"${pageContext.request.contextPath}/deletebill",
                                type:"post",
                                data:{"str":ids},
                                statusCode: {
                                    403: function() {
                                        $.messager.show({
                                            title: '温馨提示',
                                            msg: '对不起，您无权访问！',
                                            timeout: 0,
                                            showType: 'slide'
                                        });
                                        //window.location.href = "login.html";
                                    }
                                },
                                success:function (data) {
                                    if (data =="true"){
                                            var win = $.messager.progress({
                                                title:'温馨提示',
                                                msg:'正在删除...'
                                            });
                                            setTimeout(function(){
                                                $.messager.progress('close');
                                                $.messager.show({
                                                    title:'温馨提示',
                                                    msg:'删除成功',
                                                    showType:'show'
                                                });
                                            },3200);
                                        setTimeout(function(){
                                            location.href="${pageContext.request.contextPath}/showBillList";
                                        },4700);
                                    }else{
                                        $.messager.show({
                                            title:'温馨提示',
                                            msg:'删除失败！',
                                            timeout:0,
                                            showType:'slide'
                                        });
                                        return false;
                                    }
                                }
                            });
                        }else{
                            return  false;
                        }

                });
            }
            }
            $.ajax({
                url:"${pageContext.request.contextPath}/proList",
                type:"post",
                datatype:"json",
                statusCode: {
                    403: function() {
                    }
                },
                success:function (data) {
                    $.each(data.data,function (i, dom) {
                        $("#tigong").append("<option value="+dom.id+">"+dom.proName+"</option>");
                    })
                },
            });
            var  name;
            var  providerId=0;
            var  fukuan=0;
            //加载数据

            $("#btn").click(function () {
                name  =$("#billname").val();
                providerId=$("#tigong option:selected").val();
                fukuan=$("#fukuan option:selected").val();
                load(0,5);
            });
            load(0,5);

            function  load(index,PageSize) {
                $.ajax({
                    url:"${pageContext.request.contextPath}/selectbill",
                    type:"post",
                    data:{"PageIndex":index,"PageSize":PageSize,"productName":name,"providerId":providerId,"isPayment":fukuan},
                    statusCode: {
                        403: function() {
                            $.messager.alert("温馨提示","对不起，您无权访问","error");
                        }
                    },
                    success:function (data) {
                        //模拟ajax去后端读取页数，获取数据并渲染列表的过程
                        $('#billLists').html('');
                        $.each(data.data.list,function (i, item) {
                            $("#billLists").append("<tr><td><input name='checkboxs' type='checkbox' id='checkboxs' value="+item.id+"></td><td>"+item.billCode+"</td><td>"+item.productName+
                                "</td><td>"+item.provider.proName+"</td><td>"+item.totalPrice+"</td><td>"+item.paymentName+"</td><td>"
                                +item.ctratedate+"</td></td>");
                        });
                        //渲染分
                        if(data.data.totalRecords>0){
                            $('#pagination').pagination({
                                total:data.data.totalRecords,//总记录数
                                pageSize:PageSize,//页面大小
                                pageNumber:index+1,//当前页码
                                pageList: [ 5, 10, 15], //5表示页显示5条数据。
                                onSelectPage:function(pageNumber,PageSize){
                                    load(pageNumber-1,PageSize);
                                }
                            });

                        }else{
                            $('#pagination').html("<span style='color:red;font-size: 18px'>没有检索到结果~~~~~！！！！！！</span>");
                        }
                    }

                });
            }

            loginOut=function userLoginOut() {
                $.messager.confirm("温馨提示", "确定要退出吗？", function (r) {
                    if (r) {
                        location.href="${pageContext.request.contextPath}/loginout";
                    } else {
                        return false;
                    }

                });
            }

        });
    </script>
</head>
<body>
<!--头部-->
    <header class="publicHeader">
        <h1>校园超市管理系统</h1>
        <div class="publicHeaderR">
            <p><span>您好！</span><span style="color: #fff21b"> ${keyword}${login}</span> , 欢迎你！</p>
            <%--<a href="login.html">退出</a>--%>
        </div>
    </header>
<!--时间-->
    <section class="publicTime">
        <span id="time">2015年1月1日 11:11  星期一</span>
        <a href="#">温馨提示：为了能正常浏览，请使用高版本浏览器！（IE10+）</a>
    </section>
<!--主体内容-->
    <section class="publicMian ">
        <div class="left">
            <h2 class="leftH2">
                <span class="span_gn">功能列表</span>
            </h2>
            <nav>
                <ul class="list">
                    <li><a href="${pageContext.request.contextPath}/jsp/productList.jsp">商品管理</a></li>
                    <li id="active"><a href="${pageContext.request.contextPath}/jsp/billList.jsp">订单管理</a></li>
                    <li><a href="${pageContext.request.contextPath}/jsp/providerList.jsp">供应商管理</a></li>
                    <li><a href="${pageContext.request.contextPath}/jsp/userList.jsp">用户管理</a></li>
                    <li><a href="${pageContext.request.contextPath}/jsp/password.jsp">密码修改</a></li>
                    <li><a onclick="loginOut()">退出系统</a></li>
                </ul>
            </nav>
        </div>
        <div class="right">
            <div class="location">
                <strong>你现在所在的位置是:</strong>
                <span>订单管理页面</span>
            </div>
            <div class="search">
                <span>商品名称：</span>
                <input id="billname" type="text" placeholder="请输入商品的名称"/>

                <span>供应商：</span>
                <select name="tigong" id="tigong">
                    <option value="0">--请选择--</option>

                </select>

                <span>是否付款：</span>
                <select id="fukuan" name="fukuan">
                    <option value="0">--请选择--</option>
                    <option value="1">未付款</option>
                    <option value="2">已付款</option>
                </select>

                <input id="btn" type="button" value="查询"/>
                <div class="searchText">
                    <li><a href="${pageContext.request.contextPath}/jsp/billAdd.jsp">添加订单</a></li>
                    <li><a onclick="return xiugai()">修改订单</a></li>
                    <li><a onclick="return shanchu()">删除订单</a></li>
                    <li><a onclick="daochu()">导出订单</a></li>
                    <li><a href="${pageContext.request.contextPath}/jsp/billecharts.jsp ">数据展示</a></li>
                </div>
            </div>
            <!--账单表格 样式和供应商公用-->
            <table class="providerTable" cellpadding="0" cellspacing="0">
                <tr class="firstTr">
                    <th width="10%">请选择</th>
                    <th width="10%">订单编码</th>
                    <th width="20%">商品名称</th>
                    <th width="10%">供应商</th>
                    <th width="10%">订单金额</th>
                    <th width="10%">是否付款</th>
                    <th width="10%">创建时间</th>
                </tr>
                <tbody id="billLists"></tbody>
            </table>
            <div class="pagination" id="pagination" style="margin:4px 0 0 0"></div>
        </div>
    </section>

<!--点击删除按钮后弹出的页面-->
<div class="zhezhao"></div>
<div class="remove" id="removeBi">
    <div class="removerChid">
        <h2>提示</h2>
        <div class="removeMain">
            <p>你确定要删除该订单吗？</p>
            <a href="#" id="yes">确定</a>
            <a href="#" id="no">取消</a>
        </div>
    </div>
</div>

<footer class="footer">
    版权归本超市所有
</footer>

<script src="${pageContext.request.contextPath}/jsp/js/jquery.js"></script>
<script src="${pageContext.request.contextPath}/jsp/js/js.js"></script>
<script src="${pageContext.request.contextPath}/jsp/js/time.js"></script>

</body>
</html>